<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends JS_Controller {

	/**
	 * 用户首页
	 */
	public function index(){
		//print_r($_SESSION);exit;
		//$this->_view('home_index');
		if($this->session->suser->group == 1){
			$this->admini();
		}else{
			$this->users();
		}
	}

	//管理员
	private function admini(){
		//统计本月新增店铺
		$BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));
		$now_start = $BeginDate;
		//$now_end = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));

		//获取本月电子商铺
		$this->load->model('shops_mdl');
		$this->db->where('s_time >=',strtotime($now_start));
		$data['now_num'] = $this->shops_mdl->get_count();
		$data['all_num'] = $this->shops_mdl->get_count();

		//获取本月销售金额
		$this->load->model('bull_mdl');
		$this->db->where('uid','-1');
		$this->db->where('s_time >',strtotime($now_start));
		$res = $this->bull_mdl->get_sum();
		$data['now_bull'] = $res['bull'];

		//获取上个月销售金额
		$top_start = date('Y-m-01', strtotime('-1 month'));
		$top_end = date('Y-m-t', strtotime('-1 month'));

		$this->db->where('uid','-1');
		$this->db->where('s_time >=',strtotime($top_start));
		$this->db->where('s_time <=',strtotime($top_end));
		$res = $this->bull_mdl->get_sum();
		$data['top_bull'] = $res['bull'];

		//所有销售金额
		$this->db->where('uid','-1');
		$res = $this->bull_mdl->get_sum();
		$data['all_bull'] = $res['bull'];


		$this->_view('home_admin',$data);
	}

	//其他
	private function users(){
		//统计本月新增店铺
		$BeginDate=date('Y-m-01', strtotime(date("Y-m-d")));
		$now_start = $BeginDate;
		//$now_end = date('Y-m-d', strtotime("$BeginDate +1 month -1 day"));

		//获取本月电子商铺
		$this->load->model('shops_mdl');
		$this->db->where('s_time >=',strtotime($now_start));
		$data['now_num'] = $this->shops_mdl->get_count();
		$data['all_num'] = $this->shops_mdl->get_count();

		//获取本月销售金额
		$this->load->model('bull_mdl');
		$this->db->where('uid',$this->session->suser->user_id);
		$this->db->where('s_time >',strtotime($now_start));
		$res = $this->bull_mdl->get_sum();
		$data['now_bull'] = $res['bull'];

		//获取上个月销售金额
		$top_start = date('Y-m-01', strtotime('-1 month'));
		$top_end = date('Y-m-t', strtotime('-1 month'));

		$this->db->where('uid',$this->session->suser->user_id);
		$this->db->where('s_time >=',strtotime($top_start));
		$this->db->where('s_time <=',strtotime($top_end));
		$res = $this->bull_mdl->get_sum();
		$data['top_bull'] = $res['bull'];

		//所有销售金额
		$this->db->where('uid',$this->session->suser->user_id);
		$res = $this->bull_mdl->get_sum();
		$data['all_bull'] = $res['bull'];

		//权限
		$this->load->model('level_mdl');
		$this->db->where('group_id',$this->session->suser->level_id);
		$data['level'] = $this->level_mdl->get_one();

		$this->_view('home_index',$data);
	}
	

}

/* End of file Home.php */
/* Location: ./application/controllers/Home.php */